package com.cn.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.cn.backstage.entity.member_entity;
import com.cn.conn.DataManager;
import com.cn.conn.ParamSet;
import com.cn.conn.RowDatas;


public class backstage_member_dao extends DataManager {
	private RowDatas<member_entity> member;
	
	public backstage_member_dao() {
		member=new Member();
	}
	public List<member_entity> getmember(){
		String sql="SELECT * from tb_user where type='1'";
			return  queryList(sql, member);
	}
	public List<member_entity> selectmember(String name){
		String sql="SELECT * from tb_user where name like ? and type='1'";
			String aname="%"+name+"%";
			return  queryList(sql, new ParamSet(aname),member);
	}	
	public int updatemember_email(String phone,String email){
		String sql="UPDATE tb_user SET email=?   WHERE phone=?;";
		return updateExecuted(sql, new ParamSet(email,phone));
	}
	public int updatemember_yue(String phone,double num){
		String sql="UPDATE tb_user SET account_balance=?   WHERE phone=?;";
		return updateExecuted(sql, new ParamSet(num,phone));
	}
	public int addmember(String name,String phone,String email){
		String sql="INSERT into tb_user (name,phone,email,type) VALUES (?,?,?,'1')";
		return updateExecuted(sql, new ParamSet(name,phone,email));
	}
	public int deletemember(String phone){
		String sql="UPDATE tb_user SET type=0  WHERE phone=?;";
		return updateExecuted(sql, new ParamSet(phone));
	}
	private class Member implements RowDatas<member_entity>{

		@Override
		public member_entity getRowData(ResultSet rs) throws SQLException {
			member_entity member=new  member_entity();
			member.setAccount_balance(rs.getDouble("account_balance"));
			member.setEmail(rs.getString("email"));
			member.setMember_points(rs.getInt("member_points"));
			member.setPhone(rs.getString("phone"));
			member.setName(rs.getString("name"));
			member.setMember_level(rs.getInt("points_num")/100+"级");
			return member;
		}
		
	}
	
}
